/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.StrUtil
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.TextField
 *  javafx.stage.Stage
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 */
package com.gys.controller.rechargecard;

import cn.hutool.core.util.StrUtil;
import com.gys.common.business.RechargeCardUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.util.SpringUtil;
import com.gys.common.util.ValidationUtil;
import com.gys.controller.BaseController;
import com.gys.controller.rechargecard.RechargeCardExchangeController;
import com.gys.controller.rechargecard.RechargeCardLostController;
import com.gys.controller.rechargecard.RechargecardController;
import com.gys.data.rechargecard.RechargeCardInData;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@FXMLController
public class PasswordModifyController
extends BaseController
implements Initializable {
    private static final Logger log = LoggerFactory.getLogger(PasswordModifyController.class);
    @FXML
    private TextField gsrcIdModify;
    @FXML
    private TextField gsrcPasswordModify;
    @FXML
    private TextField oldPasswordModify;
    @FXML
    private TextField gsrcPasswordRepeat;
    private TextField gsrcIdSave;
    private Object currentController;

    public void initialize(URL location, ResourceBundle resources) {
        RechargecardController rechargecardController = (RechargecardController)SpringUtil.getBean("rechargecardController");
        RechargeCardLostController rechargeCardLostController = (RechargeCardLostController)SpringUtil.getBean("rechargeCardLostController");
        RechargeCardExchangeController rechargeCardExchangeController = (RechargeCardExchangeController)SpringUtil.getBean("rechargeCardExchangeController");
        String cardNo = null;
        if (rechargecardController.isForward()) {
            this.currentController = rechargecardController;
            cardNo = rechargecardController.getGsrcIdSave().getText();
            this.gsrcIdSave = rechargecardController.getGsrcIdSave();
            rechargecardController.setForward(false);
        } else if (rechargeCardLostController.isForward()) {
            this.currentController = rechargeCardLostController;
            cardNo = rechargeCardLostController.getCardNo().getText();
            this.gsrcIdSave = rechargeCardLostController.getCardNo();
            rechargeCardLostController.setForward(false);
        } else if (rechargeCardExchangeController.isForward()) {
            this.currentController = rechargeCardExchangeController;
            cardNo = rechargeCardExchangeController.getCardNo().getText();
            this.gsrcIdSave = rechargeCardExchangeController.getCardNo();
            rechargeCardExchangeController.setForward(false);
        }
        this.gsrcIdModify.setText(cardNo);
    }

    @FXML
    private void modifyPassword() {
        String cardNo = this.gsrcIdModify.getText();
        String newPassword = this.gsrcPasswordModify.getText();
        String oldPassword = this.oldPasswordModify.getText();
        String passwordRepeat = this.gsrcPasswordRepeat.getText();
        Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", null);
        if (StrUtil.isBlank((CharSequence)this.gsrcIdSave.getText())) {
            alert.setContentText("\u672a\u67e5\u8be2\u5230\u76f8\u5173\u50a8\u503c\u5361");
            alert.showAndWait();
            return;
        }
        if (StrUtil.isBlank((CharSequence)oldPassword)) {
            alert.setContentText("\u539f\u5bc6\u7801\u4e0d\u80fd\u4e3a\u7a7a");
            alert.showAndWait();
            return;
        }
        if (StrUtil.isBlank((CharSequence)newPassword)) {
            alert.setContentText("\u4fee\u6539\u5bc6\u7801\u4e0d\u80fd\u4e3a\u7a7a");
            alert.showAndWait();
            return;
        }
        if (!ValidationUtil.checkNumberStr(newPassword)) {
            alert.setContentText("\u4fee\u6539\u5bc6\u7801\u4e3a6\u4f4d\u6570\u5b57");
            alert.showAndWait();
            return;
        }
        if (newPassword.length() != 6) {
            alert.setContentText("\u4fee\u6539\u5bc6\u7801\u4e3a6\u4f4d\u6570\u5b57");
            alert.showAndWait();
            return;
        }
        if (!StrUtil.equals((CharSequence)newPassword, (CharSequence)passwordRepeat)) {
            alert.setContentText("\u4e24\u6b21\u8f93\u5165\u4e0d\u4e00\u81f4\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165");
            alert.showAndWait();
            return;
        }
        RechargeCardInData inData = new RechargeCardInData();
        inData.setGsrcId(cardNo);
        inData.setNewPassword(newPassword);
        inData.setGsrcPassword(oldPassword);
        HttpJson rsp = RechargeCardUtil.modifyPassword(inData);
        if (rsp.isSuccess()) {
            alert.setContentText("\u50a8\u503c\u5361\u5bc6\u7801\u5df2\u4fee\u6539\u6210\u529f");
            alert.showAndWait();
            this.getStage().close();
        } else {
            alert.setContentText(rsp.getMsg());
            alert.showAndWait();
        }
    }

    @FXML
    private void closeWindow() {
        this.getStage().close();
    }

    private Stage getStage() {
        Stage stage = null;
        if (this.currentController instanceof RechargecardController) {
            stage = ((RechargecardController)this.currentController).getStg();
        } else if (this.currentController instanceof RechargeCardLostController) {
            stage = ((RechargeCardLostController)this.currentController).getStg();
        } else if (this.currentController instanceof RechargeCardExchangeController) {
            stage = ((RechargeCardExchangeController)this.currentController).getStg();
        }
        return stage;
    }
}

